<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="由程序产生" prop="id">
      <el-input v-model="dataForm.id" placeholder="由程序产生"></el-input>
    </el-form-item>
    <el-form-item label="人员分类" prop="ptype">
      <el-input v-model="dataForm.ptype" placeholder="人员分类"></el-input>
    </el-form-item>
    <el-form-item label="人员类型" prop="rylx">
      <el-input v-model="dataForm.rylx" placeholder="人员类型"></el-input>
    </el-form-item>
    <el-form-item label="名称" prop="mc">
      <el-input v-model="dataForm.mc" placeholder="名称"></el-input>
    </el-form-item>
    <el-form-item label="证件类别" prop="zjlb">
      <el-input v-model="dataForm.zjlb" placeholder="证件类别"></el-input>
    </el-form-item>
    <el-form-item label="证件号码" prop="zjhm">
      <el-input v-model="dataForm.zjhm" placeholder="证件号码"></el-input>
    </el-form-item>
    <el-form-item label="证件号码" prop="realtyunitno">
      <el-input v-model="dataForm.realtyunitno" placeholder="证件号码"></el-input>
    </el-form-item>
    <el-form-item label="银行行号" prop="yhhh">
      <el-input v-model="dataForm.yhhh" placeholder="银行行号"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="lxdh">
      <el-input v-model="dataForm.lxdh" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="权利比例" prop="qlbl">
      <el-input v-model="dataForm.qlbl" placeholder="权利比例"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          id: '',
          ptype: '',
          rylx: '',
          mc: '',
          zjlb: '',
          zjhm: '',
          realtyunitno: '',
          yhhh: '',
          lxdh: '',
          qlbl: ''
        },
        dataRule: {
          id: [
            { required: true, message: '由程序产生不能为空', trigger: 'blur' }
          ],
          ptype: [
            { required: true, message: '人员分类不能为空', trigger: 'blur' }
          ],
          rylx: [
            { required: true, message: '人员类型不能为空', trigger: 'blur' }
          ],
          mc: [
            { required: true, message: '名称不能为空', trigger: 'blur' }
          ],
          zjlb: [
            { required: true, message: '证件类别不能为空', trigger: 'blur' }
          ],
          zjhm: [
            { required: true, message: '证件号码不能为空', trigger: 'blur' }
          ],
          realtyunitno: [
            { required: true, message: '证件号码不能为空', trigger: 'blur' }
          ],
          yhhh: [
            { required: true, message: '银行行号不能为空', trigger: 'blur' }
          ],
          lxdh: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          qlbl: [
            { required: true, message: '权利比例不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcdjryinfo/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.id = data.bdcDjryinfo.id
                this.dataForm.ptype = data.bdcDjryinfo.ptype
                this.dataForm.rylx = data.bdcDjryinfo.rylx
                this.dataForm.mc = data.bdcDjryinfo.mc
                this.dataForm.zjlb = data.bdcDjryinfo.zjlb
                this.dataForm.zjhm = data.bdcDjryinfo.zjhm
                this.dataForm.realtyunitno = data.bdcDjryinfo.realtyunitno
                this.dataForm.yhhh = data.bdcDjryinfo.yhhh
                this.dataForm.lxdh = data.bdcDjryinfo.lxdh
                this.dataForm.qlbl = data.bdcDjryinfo.qlbl
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcdjryinfo/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'id': this.dataForm.id,
                'ptype': this.dataForm.ptype,
                'rylx': this.dataForm.rylx,
                'mc': this.dataForm.mc,
                'zjlb': this.dataForm.zjlb,
                'zjhm': this.dataForm.zjhm,
                'realtyunitno': this.dataForm.realtyunitno,
                'yhhh': this.dataForm.yhhh,
                'lxdh': this.dataForm.lxdh,
                'qlbl': this.dataForm.qlbl
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
